package com.njxzc.igo.filter;


import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.hibernate.Session;

import com.njxzc.igo.utils.HibernateUtils;

@WebFilter(filterName="OpenSessionInViewFilter",urlPatterns="*.do")
public class Filter4_OpenSessionInViewFilter implements Filter {

	@Override
	public void destroy() {
		// TODO Auto-generated method stub

	}

	@Override
	public void doFilter(ServletRequest request, ServletResponse response,
			FilterChain filterChain) throws IOException, ServletException {
	       Session session =  HibernateUtils.getSession();
	     
	     try {
				filterChain.doFilter(request,response);
		        } finally {
		            HibernateUtils.closeSession();
		        }
		}
		   
		

	@Override
	public void init(FilterConfig arg0) throws ServletException {
		// TODO Auto-generated method stub

	}

}
